package cn.ly817.jay.service.impl;

import cn.ly817.jay.DAO.MissionDao;
import cn.ly817.jay.entity.Mission;
import cn.ly817.jay.enums.MissionGrade;
import cn.ly817.jay.service.MissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by LuoYu on 2016/12/7.
 */
@Service
public class MissionServiceImpl implements MissionService {

    @Autowired
    private MissionDao missionDao;

    /**
     * 任务状态：
     * 0-紧急任务；-3-审批未通过；-2-被指派，处理中，未提交；-1-被指派，未处理；
     * 1-已提交，组长审批中；2-审批通过任务完成；
     */
    @Override
    public int getUnhandledMissionNumByUserId(Long userId) {
        return missionDao.getUnhandledNumByProcessorId(userId);
    }

    @Override
    public List getUnhandledMissionListBypProcessorId(Long userId) {
        return missionDao.getUnhandledMissionListBypProcessorId(userId);
    }

    @Override
    public List getFinishedMissionListBypProcessorId(Long userId) {
        return missionDao.getFinishedMissionListBypProcessorId(userId);
    }

    @Override
    public Mission getMissionDetailById(Long id) {
        Mission mission =  missionDao.getMissionDetailById(id);
        mission.setScore(MissionGrade.scoreOf(mission.getMissionGrade()));
        return mission;
    }

    @Override
    public long getMissionOriginatorById(long missionId) {
        return missionDao.getMissionOriginatorById(missionId);
    }

    @Override
    public void updateStateById(long id, int dbState) {
        missionDao.updateStateById(id,dbState);
    }
}
